chore: Migrate metric descriptors to package vars#3575
Conversation
|
@SuperQ I think initial allocation when we create the collector is fine, right? We should just make sure not to allocate during scrape? |
|
Yes, but this should also help with the AST-based doc generator that people are working on. |
Migrate various metric descriptors to package vars to avoid dynamic runtime allocs. Signed-off-by: Ben Kochie <superq@gmail.com>
2ed71a7 to
d7fa7a1
Compare
|
I can't really say that I am a fan of this change. It heavily pollutes an already-crowded global namespace in the collector package. I was already going to propose that each collector should be split out into a separate package (perhaps in a v2) because of this overcrowding. Since the collectors are essentially singletons, if the objective was to make the descriptions more easily discoverable by AST, why not a compromise like declaring package-level collector vars (with the descriptions still as struct members)? e.g. type arpCollector struct {
fs procfs.FS
deviceFilter deviceFilter
entries *prometheus.Desc
logger *slog.Logger
}
var (
arpCollector = arpCollector{
entries: prometheus.NewDesc(...),
}
)The Alternatively, how about adding something like a |
Migrate various metric descriptors to package vars to avoid dynamic runtime allocs.